﻿@using Project.Resource.User        
<div style="color: #444242; width: 400px;">       
    <div class="divInpUsername">
        <p>
            <span>Username</span>
            <input style="float:left; width:250px;" onkeypress="return Enterforgot(event)" class="cf_input" type="text" id="txtUsername" />
        </p>        
    </div>
    <div class="divInpUsername">
        <p>
            <span>Email</span>
            <input style="width:250px;" onkeypress="return Enterforgot(event)" class="cf_input" type="text" id="txtEmail" />
        </p>       
    </div>
    
   <div id="divError_forgot" class="out"></div>
    <div onclick="return forgot();" class="btSend"></div>
</div>
<script type="text/javascript">
    function Enterforgot(e) {
        if (e.keyCode == 13) {
            forgot();
        }
    }
    function forgot() {
        name = $('#txtUsername').val();
        email = $('#txtEmail').val();
        if (name == "" && email == "") {
            $('#divError_forgot').html("@RegisterResource.UserName");
            return false;
        } else if (email == "" && name != "") {
            $('#divError_forgot').html("@RegisterResource.Email");
            return false;
        } else if (email != "" && name == "") {
            $('#divError_forgot').html("@RegisterResource.UserName");
            return false;
        } else if (name != "" && email != "") {
            $('#divError_forgot').html('<span style="color: #00b3f1; font-weight: bold;">Processing data...</span>');
            var url = '/User/ForgotPassword';
            $.post(url, {
                user: name,
                email: email
            },
                function (data) {
                    if (data == 1) {
                        $('.out').removeClass('output_msg');
                        $('.out').addClass('output_msg');
                        $('#divError_forgot').html('@RegisterResource.ForgotSuccess');
                    }
                    if (data == "0") {
                        $('#divError_forgot').html('@RegisterResource.ForgotFailed');
                    }
                    if (data == "2") {
                        location.href = "/";
                    }
                }
            );
        }
    }

    function reset() {
        $('#txtUsername').val('');
        $('#txtEmail').val('');
    }

    $(document).ready(function () {
        $('#txtUsername').focus();
    });
</script>